// pages/person/person.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:"王先生",
    tel:"135 **** 2060",
    shoppingNumber: '3',
    detail1:[
      {
        image:"../images/person/wodedingdan.png",
        text: "我的订单",
        id: "../myOrder/myOrder"
      },
      {
        image: "../images/person/yueduizhangdan.png",
        text: "月对账单",
        id: "../monthlyStatement/monthlyStatement"
      },
      {
        image: "../images/person/xiaofeimingxi.png",
        text: "消费明细",
        id: "../consumptionDetails/consumptionDetails"
      },
      {
        image: "../images/person/jiaokuanchaxun.png",
        text: "交款查询",
        id: "../paymentRecord/paymentRecord"
      },  

    ],
    detail2: [
      {
        image: "../images/person/wodejifen.png",
        text: "我的积分",
        id: ""
      },
      {
        image: "../images/person/wodekaquan.png",
        text: "我的卡券",
        id: "../cashCouponDetail/cashCouponDetail"
      },
      {
        image: "../images/person/dizhiguanli.png",
        text: "地址管理",
        id: "../address/address"
      },
      {
        image: "../images/person/shenqingtuanzhang.png",
        text: "申请团长",
        id: "../chiefApplication/chiefApplication"
      },   
    ],
    detail3: [
      {
        image: "../images/person/tingnai.png",
        text: "临时停奶",
        id: "/biangeng/pages/tingnai/tingnai"
      },
      {
        image: "../images/person/huifu.png",
        text: "恢复送奶",
        id: "/biangeng/pages/huifu/huifu"
      },
      {
        image: "../images/person/bianpinzhong.png",
        text: "变更品种",
        id: "/biangeng/pages/biangengpinzhong/biangengpinzhong"
      },
      {
        image: "../images/person/bianshuliang.png",
        text: "变更数量",
        id: "/biangeng/pages/biangengshuliang/biangengshuliang"
      },
    ],
    detail4: [
      {
        image: "../images/person/naixiang.png",
        text: "我要装箱",
        id: 'zhuangxiang',
      },
      {
        image: "../images/person/xiguan.png",
        text: "我要吸管",
        id:'xiguan',
      },
      {
        image: "../images/person/beiyongyaoshi.png",
        text: "我要钥匙",
        id: 'yaoshi',
      },
      {
        image: "../images/person/qitapaidan.png",
        text: "其他派单",
        id: 'qita',
      },
    ],        
    thNumber:[1,2,3,4,5,6],
    elasticFrameBtn1:true,
    elasticFrameBtn2:true,
    thPatternEwm:'../images/person/ewm.png',
    paidanShow:{
        zhuangxiangBtn: true,
        xiguan:true,
        yaoshi:true,
        qita:true
      },
    paidanTextarea:{
      textareaText:'', 
      textareaCustomer:true, 
      qitaSuccess:true, 
      customerNumber:2
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setTabBarBadge({//购物车数量
      index: 1,
      text: this.data.shoppingNumber,
      color: "black"
    })
  },
  goHtml: function (event) {
    var newsid = event.currentTarget.dataset.newsid
    wx.navigateTo({
      url: newsid
      // 跳转各个页面详情
    })
  },
  goBiangeng: function (event) {//跳到变更
    var newsid = event.currentTarget.dataset.newsid
    wx.navigateTo({
      url: newsid
    })
  },
  goPaidan: function (event) {//派单
    var newsid = event.currentTarget.dataset.newsid;
    var paidanShow = this.data.paidanShow
    if (newsid =='zhuangxiang'){
      paidanShow.zhuangxiangBtn=false
    } else if (newsid == 'xiguan'){
      paidanShow.xiguan = false
     
    } else if (newsid == 'yaoshi') {
      paidanShow.yaoshi = false

    } else if (newsid == 'qita') {
      paidanShow.qita = false

    }
    this.setData({
      paidanShow: paidanShow
    })
    this.qitaBtn()
  },
  //提货方式
  patternNumber:function(){
    wx.hideTabBar();//隐藏tabBar
    var elasticFrameBtn1 = this.data.elasticFrameBtn1;
    elasticFrameBtn1 = false;
    this.setData({
      elasticFrameBtn1: elasticFrameBtn1
    })
    
  },
  elasticFrameHide: function () {
    this.setData({
      elasticFrameBtn1: true,
      elasticFrameBtn2: true,
    })
    wx.showTabBar();//显示tabBar
  },
  patternEwm: function () {
    wx.hideTabBar();//隐藏tabBar
    var elasticFrameBtn2 = this.data.elasticFrameBtn1;
    elasticFrameBtn2 = false;
    this.setData({
      elasticFrameBtn2: elasticFrameBtn2
    })
  },
  qitaBtnHide: function () {
    var paidanShow = this.data.paidanShow
      paidanShow.zhuangxiangBtn = true
      paidanShow.xiguan = true
      paidanShow.yaoshi = true
      paidanShow.qita =true
    this.setData({
      paidanShow: paidanShow
    })
  }, 
  paidanBtnHide:function(){
    var paidanShow = this.data.paidanShow
    paidanShow.zhuangxiangBtn = true
    paidanShow.xiguan = true
    paidanShow.yaoshi = true
    paidanShow.qita = true
    this.setData({
      paidanShow: paidanShow
    })
    var paidanShow = this.data.paidanShow
    paidanShow.qita = true;
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.qitaSuccess = false;
    this.setData({
      paidanShow: paidanShow,
      paidanTextarea: paidanTextarea
    })
    this.qitaDown()   
  },
  // 其他派单
  qitaBtn: function () {
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.qitaBtn = !paidanTextarea.qitaBtn;
    paidanTextarea.textareaCustomer = true;
    paidanTextarea.textareaText=''
    this.setData({
      paidanTextarea: paidanTextarea
    })
  },
  qitaBtnSuccess: function () {
    var paidanShow = this.data.paidanShow
    paidanShow.qita = true;
    var paidanTextarea=this.data.paidanTextarea;
    paidanTextarea.qitaSuccess = false;
    this.setData({
      paidanShow: paidanShow,
      paidanTextarea: paidanTextarea
    })
    this.qitaDown()

  },
  qitaBtnSuccessHide: function () {
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.qitaSuccess = true;
    this.setData({
      paidanTextarea: paidanTextarea
    });
  },
  qitaDown() { //倒计时函数
    var that = this
    var customerDown = setInterval(function () {
      var paidanTextarea = that.data.paidanTextarea;
      var customerNumber = paidanTextarea.customerNumber;
      if (customerNumber <= 1) {
        customerNumber=2
        paidanTextarea.qitaSuccess=true
        that.setData({
          paidanTextarea: paidanTextarea
        })
        clearInterval(customerDown);
       
      } else {
        customerNumber--;
        
      }
      paidanTextarea.customerNumber = customerNumber
      that.setData({
        paidanTextarea: paidanTextarea
      })
    }, 1000);

  },
  textareaqita(e) {//其他留言
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.textareaCustomer = e.detail.value.replace(/\s+/g, '');
    paidanTextarea.textareaText = paidanTextarea.textareaCustomer
    this.setData({
      paidanTextarea: paidanTextarea
    });
    this.qitaText()
  },
  qitaText: function () {
    var paidanTextarea = this.data.paidanTextarea;
    if (this.data.paidanTextarea.textareaCustomer) {
      this.data.paidanTextarea.textareaCustomer=false;
      this.data.paidanTextarea.customerNumber=2
      this.setData({
        paidanTextarea: paidanTextarea
      });
    } else {
      this.data.paidanTextarea.textareaCustomer = true
      this.setData({
        paidanTextarea: paidanTextarea
      });
    }
  },

})